package com.xdkj.model.dao.impl;

import com.xdkj.commons.util.RunnerUtil;
import com.xdkj.model.dao.TUserDao;
import com.xdkj.model.entity.TUser;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.SQLException;
import java.util.List;

/**
 * ClassName TUserDaoImpl
 * Description:
 *
 * @Author:一尘
 * @Version:1.0
 * @Date:2021-11-02-9:46
 */
public class TUserDaoImpl implements TUserDao {
    private static final Logger log = LoggerFactory.getLogger(TUserDaoImpl.class);
    //日志输出
    private QueryRunner runner = RunnerUtil.getRunner();

    @Override
    public List<TUser> queryAllUsers() {
        log.info(this.getClass().getSimpleName(), "查询所有的用户数据");
        List<TUser> list = null;
        try {
            list = runner.query("select * from t_user", new BeanListHandler<>(TUser.class));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }

    @Override
    public List<TUserDao> queryAllByPage(int page, int limit) {
        return null;
    }

    @Override
    public TUser queryById(int id) {
        return null;
    }

    @Override
    public TUser queryByName(String name) {
        TUser tUser = null;
        try {
            tUser = runner.query("select * from t_user where username = ?", new BeanHandler<>(TUser.class), name);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return tUser;
    }

    @Override
    public boolean addTUser(TUser tUser) {
        return false;
    }

    @Override
    public boolean updateTUser(TUser tuser) {
        return false;
    }

    @Override
    public boolean deleteTUser(int id) {
        return false;
    }
}
